<?php 
//类的实战
?>

<?php 
    //声明一个Page类
    class Page
    {
        //主要内容
        public $content;

        //页面标题
        public $title = "TLA Consulting Pty Ltd";

        //元标记
        public $keywords = "TLA Consulting Three Letter Abreviation,
                            some of my best friends are search engines";
        
        //菜单
        public $buttons = array( "Home" => "home.php",
                                  "Contact" => "contact.php",
                                  "Services" => "services.php",
                                  "Site Map" => "map.php"
                                );

        //
        public function _set($name, $value)
        {
            $this->$name = $value;
        }

        //
        public function Display()
        {
            echo "<html>\n<head>\n";
            $this -> DisplayTitle();
            $this -> DisplayKeywords();
            $this -> DisplayStyles();
            echo "</head>\n<body>\n";
            $this -> DisplayHeader();
            $this -> DisplayMenu($this->buttons);
            echo $this->content;
            $this -> DisplayFooter();
            echo "</body>\n</html>\n";
        }

        public function DisplayTitle()
        {
            echo "<title>".$this->title."</title>";
        }

        public function DisplayKeywords()
        {
            echo "<meat name='keywords' content='".$this->keywords."' />";
        }

        public function DisplayStyles()
        {
            ?>
            <link href="styles.css" type="text/css" rel="stylesheet">
            <?php
        }

        public function DisplayHeader()
        {
            ?>
            <!-- page header -->
            <header>
                <img src="logo.gif" alt="TLA log" height="70" width="70" />
                <h1>TLA Consulting</h1>
            </header>
            <?php
        }

        public function DisplayMenu($buttons)
        {
            echo "<!--menu --><nav>";
            while (list($name, $url) = each($buttons)) {
                $this->DisplayButton($name, $url, !$this->IsURLCurrentPage($url));
            }
            echo "</nav>\n";
        }

        public function IsURLCurrentPage($url)
        {
            if(strpos($_SERVER['PHP_SELF'], $url)===false)
            {
                return false;
            }
            else {return true;}
        }

        public function DisplayButton($name, $url, $active=true)
        {
            if ($active) { ?>
            <div class="menuitem">
            <a href="<?=$url?>">
            <img src="s-logo.gif" alt="" height="20" width="20" />
            <span class="menutext"><?=$name?></span>
            </a>
            </div>
            <?php
        }
        }

        public function DisplayFooter()
        {
            ?>
            <!-- page footer -->
            <footer>
                <p>&copy; TLA Consulting Pty Ltd. <br />
                Please see our
                <a href="legal.php">legal information page</a>.</p>
            </footer>
        <?php
        }
    }

?>